<?php

$test = 0;

$plugin['version'] = '0.1';
$plugin['author'] = 'Mykhailo Kotsur';
$plugin['author_uri'] = 'http://sotomajor.org.ua/';
$plugin['description'] = 'Allows to embed your smug-mug thumbnails into your web-site.';

// Plugin types:
// 0 = regular plugin; loaded on the public web side only
// 1 = admin plugin; loaded on both the public and admin side
// 2 = library; loaded only when include_plugin() or require_plugin() is called
$plugin['type'] = 0;


@include_once('zem_tpl.php');

if (0) {
?>
# --- BEGIN PLUGIN HELP ---

Please, see more details at http://code.google.com/p/smugplug/

# --- END PLUGIN HELP ---
<?php
}

# --- BEGIN PLUGIN CODE ---

if ($test !== 1) {
    global $txpcfg;
    require_once($txpcfg['txpath'].'/include/str_smugplug_lib/phpSmug/phpSmug.php');
    require_once($txpcfg['txpath'].'/include/str_smugplug_lib/str_SmugMug.php');
    require_once($txpcfg['txpath'].'/include/str_smugplug_lib/str_SmugMugEntity.php');
    require_once($txpcfg['txpath'].'/include/str_smugplug_lib/str_SmugMugAlbum.php');
    require_once($txpcfg['txpath'].'/include/str_smugplug_lib/str_SmugMugImage.php');
    require_once($txpcfg['txpath'].'/include/str_smugplug_lib/str_ImageDimensions.php');
} else {
    require_once('str_smugplug_lib/phpSmug/phpSmug.php');
    require_once('str_smugplug_lib/str_SmugMug.php');
    require_once('str_smugplug_lib/str_SmugMugEntity.php');
    require_once('str_smugplug_lib/str_SmugMugAlbum.php');
    require_once('str_smugplug_lib/str_SmugMugImage.php');
    require_once('str_smugplug_lib/str_ImageDimensions.php');
}

function str_smug_image($params) {
    extract($params, EXTR_PREFIX_ALL, 'param');
	
    if (empty($param_id) || empty($param_key)) {
		return false;
	}
    
    $smugMug = new str_SmugMug();
    $image = $smugMug->getImageByIdAndKey($param_id, $param_key);
    if ($image instanceof str_SmugMugImage === false) {
        return '';
    }
    
    $imageSizeType = (isset($param_height) || isset($param_width)) ? 
                        str_ImageDimensions::typeCustom : str_ImageDimensions::typeMedium;

    if (isset($param_linked) && $param_linked == 'false' || $param_linked == '0') {
        return $image->getImgTagHtml($imageSizeType, array($param_width, $param_height));
    } else {
        return $image->getLinkedImgTagHtml($imageSizeType, array($param_width, $param_height));
    }
}

/*
function str_smug_random_thumb($params) {
	extract($params, EXTR_PREFIX_ALL, 'param');
	
	if (empty($param_login)) {
		return false;
	}
	
	$smugMug = new str_SmugMug($param_login);
	return $smugMug->getRandomAlbum()->getRandomImage()->getTinyUrl();
}
*/
function str_smug_latest_albums_thumbs($params) {
	extract($params, EXTR_PREFIX_ALL, 'param');
	
	if (empty($param_login)) {
		return false;
	}
    
    if (empty($param_count) || ((int)$param_count > 0 === false)) {
        $param_count = 5;
    }
    
    $smugMug = new str_SmugMug($param_login);
    $albums = $smugMug->getAlbumList();

    $links = array();
    for($i = 0; $i < $param_count; $i++) {
        $links[] = $albums[$i]->getRandomImage()->getLinkedImgTagHtml(str_ImageDimensions::typeTiny);
    }
    
    return implode("\n", $links);
}


# --- END PLUGIN CODE ---
if ($test === 1) {
    echo str_smug_latest_albums_thumbs(array('login' => 'sotomajor'));

    //echo str_smug_image(array('id' => '594396652','key' => 'gSq5y', 'linked' => '1', 'width' => '600', 'height' => '200'));
}
